home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / wschesb1.zip / SRC / HITTEST.C < prev    next >
C/C++ Source or Header  |  1994-03-15  |  3KB  |  103 lines

  1. /*
  2.   C source for Winsock Chess
  3.   
  4.   Revision 1994-03-15
  5.   Modified by Donald Munro for use as a 2 player chess game over a 
  6.   WINSOCK layer on a TCP (or other WinSock supporting) network.
  7.   Source code and make files for MS Visual C/C++ V1.00/1.50.
  8.   February/March 1994
  9.   All GNU copyright and distribution conditions as described below and in the
  10.   file COPYING also apply to WinSock Chess.
  11.   This module is adapted from GNU Chess.
  12.   
  13.   C source for GNU CHESS
  14.  
  15.   Revision: 1990-09-30
  16.  
  17.   Modified by Daryl Baker for use in MS WINDOWS environment
  18.  
  19.   This file is part of CHESS.
  20.  
  21.   CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  22.   WARRANTY.  No author or distributor accepts responsibility to anyone for
  23.   the consequences of using it or for whether it serves any particular
  24.   purpose or works at all, unless he says so in writing.  Refer to the CHESS
  25.   General Public License for full details.
  26.  
  27.   Everyone is granted permission to copy, modify and redistribute CHESS, but
  28.   only under the conditions described in the CHESS General Public License.
  29.   A copy of this license is supposed to have been given to you along with
  30.   CHESS so you can know your rights and responsibilities.  It should be in a
  31.   file named COPYING.  Among other things, the copyright notice and this
  32.   notice must be preserved on all copies.
  33. */
  34.  
  35. #define NOATOM 
  36. #define NOCLIPBOARD
  37. #define NOCREATESTRUCT
  38. #define NOFONT
  39. #define NOSOUND
  40. #define NOWH
  41. #define NOKANJI
  42.  
  43. #include <windows.h>
  44. #include <windowsx.h>
  45. #include <stdio.h>
  46.  
  47. #include "defs.h"
  48.  
  49. static int deltay;
  50. static HRGN hitrgn[8];
  51.  
  52. void InitHitTest ( void )
  53. {
  54.    POINT ptls[4];
  55.    POINT toppt, botpt;
  56.    int i;
  57.    for (i=0; i<8; i++) {
  58.       QuerySqOrigin ( i, 0, ptls+0 );
  59.       QuerySqOrigin ( i, 8, ptls+1 );
  60.       QuerySqOrigin ( i+1, 8, ptls+2 );
  61.       QuerySqOrigin ( i+1, 0, ptls+3 );
  62.       hitrgn[i] = CreatePolygonRgn ( ptls, 4, WINDING);
  63.    }
  64.       QuerySqOrigin ( 0, 0, &botpt );
  65.       QuerySqOrigin ( 0, 8, &toppt );
  66.       deltay = botpt.y-toppt.y;
  67.  }
  68.  
  69. void Hittest_Destructor (VOID)
  70. {
  71.    int i;
  72.    for (i=0; i<8; i++)
  73.       DeleteObject ( hitrgn[i] );
  74. }
  75.  
  76. static int HorzHitTest ( int x, int y)
  77. {
  78.    int i;
  79.  
  80.    for ( i=0; i<8; i++) {
  81.       if ( PtInRegion ( hitrgn[i],x,y) ) return i;
  82.    }
  83.    return -1;
  84. }
  85.  
  86. int HitTest ( int x, int y)
  87. {
  88.    int xsq, ysq;
  89.    POINT sq00;
  90.  
  91.    xsq = HorzHitTest ( x, y );
  92.    if (xsq==-1) return -1;
  93.  
  94.    QuerySqOrigin ( 0,0, &sq00);
  95.  
  96.    if ( y > sq00.y ) return -1;
  97.    if ( y < (sq00.y-deltay) ) return -1;
  98.  
  99.    ysq = 7 - (y - (sq00.y-deltay) ) / (deltay/8);
  100.    return ( ysq*8 + xsq );
  101. }
  102.  
  103.